﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Solidi
{
	public class DependencyReference : IDependencyReference
	{
		private int _count;
		private object _value;
		private object _token;

		public DependencyReference(object value, object token)
		{
			_value = value;
			_token = token;
			_count = 1;
		}

		public bool Unreferenced
		{
			get
			{
				return _count <= 0;
			}
		}

		public object Token
		{
			get
			{
				return _token;
			}
		}

		public object Value
		{
			get
			{
				return _value;
			}
		}

		public void Dispose()
		{
			IDisposable disposable = _value as IDisposable;

			if (disposable != null)
			{
				disposable.Dispose();
			}
		}

		public void Increment()
		{
			_count++;
		}

		public void Decrement()
		{
			_count--;
		}
	}
}
